package com.kanqiubao.kq.fragment.recoding;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.kanqiubao.kq.R;
import com.kanqiubao.kq.adapter.main.RecodingListAdapter;
import com.kanqiubao.kq.adapter.recoding.RecodingDayListAdapter;
import com.kanqiubao.kq.fragment.BaseFragment;
import com.kanqiubao.kq.utils.AppConfig;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class RecodingDayPageFragment extends BaseFragment<String> {
    private RecyclerView mGrid;
    private RecyclerView mListRecy;
    private RecodingDayListAdapter mRecodingDayListAdapter;
    private RecodingListAdapter mRecodingListAdapter;

    private TextView mCurrentSelect;

    @Override
    protected int getLayoutId() {
        return R.layout.recoding_sc_list_page_layout;
    }

    @Override
    protected void initView() {
        mGrid = findView(R.id.g_recy_id);
        mListRecy = findView(R.id.recy_id);
        mRecodingListAdapter = new RecodingListAdapter(R.layout.recording_list_layout);
        mListRecy.setAdapter(mRecodingListAdapter);
        mListRecy.setLayoutManager(new LinearLayoutManager(getActivity()));
        mCurrentSelect = findView(R.id.current_time_id);
        setDayData();
    }

    @Override
    protected void initData() {
    }

    private void setDayData() {
        mRecodingDayListAdapter = new RecodingDayListAdapter(R.layout.recoding_sc_rl_item_layout);
        mGrid.setAdapter(mRecodingDayListAdapter);
        mGrid.setLayoutManager(new GridLayoutManager(getActivity(), 7));
        String month = getmTitle();
        String[] time = month.split(",");
        int day = AppConfig.getDaysByYearMonth(Integer.valueOf(time[0]), Integer.valueOf(time[1]));//月的天数
        int week = AppConfig.getWeek(time[0] + "-" + Integer.valueOf(time[1]) + "-01", null);//每月01号星期几

        List<String> dayTime = new ArrayList<>();
        int temp = week - 1;
        for (int i = 0; i < temp; i++) {
            dayTime.add("-1");//前面空白的
        }
        for (int i = 0; i < day; i++) {
            dayTime.add((i + 1) + "");//计算出日期

        }
        mRecodingDayListAdapter.addData(dayTime);
        mCurrentSelect.setText(time[0] + "年" + Integer.valueOf(time[1]) + "月");
        mRecodingDayListAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                //选中查询数据
                if (mRecodingDayListAdapter.getItem(position).equals("-1")) {
                    return;
                }
                mRecodingDayListAdapter.setmClickPostion(position);
                test();
            }
        });
    }

    private void test() {
        List<String> ls = new ArrayList<>();
        ls.add("");
        ls.add("");
        ls.add("");
        ls.add("");
        ls.add("");
        mRecodingListAdapter.addData(ls);
    }
}
